* Paddy Carter, Nicolas Van de Sijpe, and Raphael Calel, 10-June-2020
* Firm-level simulations


clear all
set more off
version 15.1


/* Set path to correct folder */ 
local DISK Nicolas // options: Nicolas, Paddy
if "`DISK'"=="Paddy" {
	cd "C:\Users\Paddy Carter\Dropbox\Development Finance Institutions\Firm"
}
else if "`DISK'"=="Nicolas" {
	cd "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Firm"
	local figures "C:\Users\ec1nv\Dropbox\My Documents\My Papers\Development Finance Institutions\Paper\Figures"
}
else {
	di as error "Incorrect content for local DISK"
	exit
}


run elusivefirms.do
graph set window fontface "Palatino Linotype"


*******************************************************************************************
* MAIN GRAPH
*******************************************************************************************
* No additionality; larger budget, larger variance in pc, less in er.
elusivefirms, musd1(2) musd2(2) musd3(2) ersd(0.25) dfilo(2) dfihi(4) psmin(2) dfbudg(.2) nI(500) mechanism(random)
twoway (histogram pc if dfi_inv==1, width(.1) start(0) lcolor(gs10) fcolor(gs10) freq) /// 
(histogram pc if ps_inv==1, width(.1) start(0) lcolor(black) fcolor(none) freq), /// 
scheme(plotplainblind) legend(order(1 "DFIs" 2 "Private")) title("Predicted probability of private investment") subtitle("Distributions of project characteristics, DFI and private")


* Keep only funded projects.
keep if dfi_inv==1 | ps_inv==1


* Probit
probit ps_inv pc
predict pr_probit, pr
label variable pr_probit "Predicted probability of private investment"
twoway (histogram pc if dfi_inv==1, width(.1) start(0) lcolor(gs10) fcolor(gs10) freq yaxis(1) legend(off)) /// 
(histogram pc if ps_inv==1, width(.1) start(0) lcolor(black) fcolor(none) freq legend(off)) /// 
|| (scatter pr_probit pc, msymbol(+) msize(tiny) mcolor(black) yaxis(2) yscale(range(0 1) axis(2)) legend(off)), /// 
scheme(plotplainblind)
graph export "`figures'/firms_probit.pdf", replace


count if dfi_inv == 1
scalar dfiinv = r(N)
count if dfi_inv == 1 & pr_probit < 0.5
scalar additional = r(N)
di "Percentage of DFI-funded projects deemed additional: " (additional/dfiinv)*100 "%"


*******************************************************************************************
* ADDITIONAL GRAPHS
*******************************************************************************************
/* 1. full additionality, large errors. */
elusivefirms, musd1(2) musd2(2) musd3(2) ersd(1.5) dfilo(0) dfihi(2) psmin(2) dfbudg(.2) nI(500)  mechanism(random)
twoway (histogram pc if dfi_inv==1, width(.2) lcolor(gs10) fcolor(gs10) freq) /// 
(histogram pc if ps_inv==1, width(.2) lcolor(black) fcolor(none) freq), legend(off) scheme(plotplainblind)
graph export "`figures'/pchisto_fulladd_hierror.pdf", replace


/* 2. full additionality, small errors.  */
elusivefirms, musd1(2) musd2(2) musd3(2) ersd(0.1) dfilo(0) dfihi(2) psmin(2) dfbudg(.2) nI(500)  mechanism(random)
twoway (histogram pc if dfi_inv==1, width(.2) lcolor(gs10) fcolor(gs10) freq) /// 
(histogram pc if ps_inv==1, width(.2) lcolor(black) fcolor(none) freq), legend(off) scheme(plotplainblind)
graph export "`figures'/pchisto_fulladd_loerror.pdf", replace


/* 3. no additionality, large DFI budget. */ 
elusivefirms, musd1(2) musd2(2) musd3(2) ersd(0.1) dfilo(2) dfihi(4) psmin(2) dfbudg(.3) nI(500) mechanism(random)
twoway (histogram pc if dfi_inv==1, width(.2) lcolor(gs10) fcolor(gs10) freq) /// 
(histogram pc if ps_inv==1, width(.2) lcolor(black) fcolor(none) freq), legend(off) scheme(plotplainblind)
graph export "`figures'/pchisto_noadd_hibudg.pdf", replace


/* 4. no additionality, small DFI budget. */
elusivefirms, musd1(2) musd2(2) musd3(2) ersd(0.1) dfilo(2) dfihi(4) psmin(2) dfbudg(.1) nI(500) mechanism(random)
twoway (histogram pc if dfi_inv==1, width(.2) lcolor(gs10) fcolor(gs10) freq) /// 
(histogram pc if ps_inv==1, width(.2) lcolor(black) fcolor(none) freq), legend(off) scheme(plotplainblind)
graph export "`figures'/pchisto_noadd_lobudg.pdf", replace
